package com.controller;

import com.comment.CommentResult;
import com.domain.entity.Picture;
import com.domain.req.AddPictureReq;
import com.domain.req.UpdatePictureReq;
import com.service.PictureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图相关业务接口层
 */
@CrossOrigin
@RestController
@Slf4j
@RequestMapping("/picture")
public class PictureController {
    @Autowired
    private PictureService pictureService;

    /**
     * 根据轮播图id查询轮播图信息
     */
    @GetMapping("/getById/{id}")
    public CommentResult<Picture> getById(@PathVariable("id") Integer id) {
        Picture picture = pictureService.getById(id);
        return CommentResult.success(picture);
    }

    /**
     * 查询所有轮播图信息
     */
    @RequestMapping("/list")
    public CommentResult<List<Picture>> list() {
        List<Picture> pictureList = pictureService.list();
        return CommentResult.success(pictureList);
    }

    /**
     * 新增轮播图信息
     */
    @PostMapping("/addPicture")
    public CommentResult<Void> addPicture(@RequestBody AddPictureReq addPictureReq) {
        pictureService.addPicture(addPictureReq);
        return CommentResult.success();
    }

    /**
     * 根据轮播图id删除轮播图信息
     */
    @DeleteMapping("/deleteById/{id}")
    public CommentResult<Void> deleteById(@PathVariable("id") Integer id) {
        pictureService.deleteById(id);
        return CommentResult.success();
    }

    /**
     * 根据id修改轮播图信息
     */
    @PutMapping("/updateById")
    public CommentResult<Void> updateById(@RequestBody UpdatePictureReq updatePictureReq) {
        pictureService.updateById(updatePictureReq);
        return CommentResult.success();
    }
}
